const mongoose = require('mongoose');
mongoose.connect(`mongodb://localhost:27017/cxsx`);

const { Schema } = mongoose;

const user = new Schema({
    userId: String,
    password: String,
    name: String,
    avatarImg: String,
    chatList: Array, //存放聊天id
    // {
    //     id:String,
    //     latestTime:String //此会话最后一次活跃时间
    // }
    regDate: String
})
const chat = new Schema({
    id: String,
    name: String,
    firstKey: String,
    secondKey: String, //md5哈希的结果
    record: Array,
    /*
    {
        userId:String,
        date:String,
        content:String
    }    
    */
    isEst: { //是否建立(邀请方是否进入)
        type: Boolean,
        default: false
    },
    isDel: { //是否删除(邀请方是否)
        type: Boolean,
        default: false
    },
    userList: Array, //存放会话的用户idlist
    // {
    //     userId:String,
    //     date:String,
    // }
    amount: Number, //会话最大人数
    createTime: String, //创建时间
    latestTime: String, //最后一次活动时间0
})

module.exports = {
    Users: mongoose.model('user', user),
    Chats: mongoose.model('chat', chat)
}